package org.example.task4;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MysqlTest {
    static MysqlUtil db = new MysqlUtil();

    public static void main(String[] args) throws Exception {
        Connection conn = db.getConn();
        PreparedStatement pstm = null;
        String sql_insert = "insert into student(name, English, Math, Computer) values(?,?,?,?)";
        pstm = conn.prepareStatement(sql_insert);

        //填充sql语句中的？
        pstm.setString(1, "scofield");
        pstm.setString(2, "45");
        pstm.setString(3, "89");
        pstm.setString(4, "100");

        //使用executeUpdate函数执行sql语句
        int row = pstm.executeUpdate();
        System.out.println("新增学生信息成功" + row + "行受到影响");

        String sql_select = "SELECT English FROM student where name = ?";
        pstm = conn.prepareStatement(sql_select);
        pstm.setString(1, "scofield");
        ResultSet rs= pstm.executeQuery();

        while (rs.next()) {
            System.out.println("scofield的英语成绩为：" + rs.getInt("English"));
        }

        //释放对数据库的连接
        db.closeConn(rs, pstm, conn);

    }
}
